package com.ruoyi.datascreen.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.datascreen.domain.vo.DsLargeScreenVo;
import com.ruoyi.datascreen.domain.bo.DsLargeScreenBo;
import com.ruoyi.datascreen.service.IDsLargeScreenService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大屏信息
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/datascreen/largeScreen")
public class DsLargeScreenController extends BaseController {

    private final IDsLargeScreenService iDsLargeScreenService;

    /**
     * 查询大屏信息列表
     */
    @SaCheckPermission("datascreen:largeScreen:list")
    @GetMapping("/list")
    public TableDataInfo<DsLargeScreenVo> list(DsLargeScreenBo bo, PageQuery pageQuery) {
        return iDsLargeScreenService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出大屏信息列表
     */
    @SaCheckPermission("datascreen:largeScreen:export")
    @Log(title = "大屏信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DsLargeScreenBo bo, HttpServletResponse response) {
        List<DsLargeScreenVo> list = iDsLargeScreenService.queryList(bo);
        ExcelUtil.exportExcel(list, "大屏信息", DsLargeScreenVo.class, response);
    }

    /**
     * 获取大屏信息详细信息
     *
     * @param largeScreenId 主键
     */
    @SaCheckPermission("datascreen:largeScreen:query")
    @GetMapping("/{largeScreenId}")
    public R<DsLargeScreenVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long largeScreenId) {
        return R.ok(iDsLargeScreenService.queryById(largeScreenId));
    }

    /**
     * 新增大屏信息
     */
    @SaCheckPermission("datascreen:largeScreen:add")
    @Log(title = "大屏信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DsLargeScreenBo bo) {
        return toAjax(iDsLargeScreenService.insertByBo(bo));
    }

    /**
     * 修改大屏信息
     */
    @SaCheckPermission("datascreen:largeScreen:edit")
    @Log(title = "大屏信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DsLargeScreenBo bo) {
        return toAjax(iDsLargeScreenService.updateByBo(bo));
    }

    /**
     * 删除大屏信息
     *
     * @param largeScreenIds 主键串
     */
    @SaCheckPermission("datascreen:largeScreen:remove")
    @Log(title = "大屏信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{largeScreenIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] largeScreenIds) {
        return toAjax(iDsLargeScreenService.deleteWithValidByIds(Arrays.asList(largeScreenIds), true));
    }
}
